package com.lanchetech.user.controller;

import com.lanchetech.bean.request.RoomReq;
import com.lanchetech.bean.request.RoomSpuReq;
import com.lanchetech.bean.request.WsSendToUserReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.QueryRecordResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.RoomDetailVO;
import com.lanchetech.bean.vo.RoomSpuVO;
import com.lanchetech.bean.vo.RoomStatisticsVO;
import com.lanchetech.bean.vo.RoomVO;
import com.lanchetech.entity.Room;
import com.lanchetech.entity.User;
import com.lanchetech.user.service.RoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "直播间接口", tags = "直播间接口")
@RequestMapping("/api/room")
@RestController
public class RoomController {

    @Autowired
    RoomService roomService;

    @ApiOperation("获取直播间详情")
    @GetMapping("/getRoomDetail")
    public ResultData<RoomDetailVO> getRoomDetail(@AuthenticationPrincipal User user, @RequestParam("id") Long id) {
        return roomService.getRoomDetail(user, id);
    }

    @ApiOperation("获取直播间统计数据")
    @GetMapping("/getRoomStatistics")
    public ResultData<List<RoomStatisticsVO>> getRoomStatistics(@RequestParam("roomId") Long roomId) {
        return roomService.getRoomStatistics(roomId);
    }

    @ApiOperation("编辑直播间")
    @PostMapping("/editRoom")
    public ResultData<Long> editRoom(@RequestBody Room room) {
        return roomService.editRoom(room);
    }

    @ApiOperation("关闭直播间")
    @GetMapping("/closeRoom")
    public BaseResp closeRoom(@RequestParam("id") Long id) {
        return roomService.closeRoom(id);
    }

    @ApiOperation("获取直播间列表")
    @PostMapping("/getRoomPage")
    public ResultData<BasePageResp<RoomVO>> getRoomPage(@AuthenticationPrincipal User user,@RequestBody RoomReq req) {
        return roomService.getRoomPage(user,req);
    }

    @ApiOperation("获取我的直播间列表")
    @PostMapping("/getMyRoomPage")
    public ResultData<BasePageResp<Room>> getMyRoomPage(@RequestBody RoomReq req) {
        return roomService.getMyRoomPage(req);
    }

    @ApiOperation("删除直播间")
    @GetMapping("/deleteRoom")
    public BaseResp deleteRoom(@RequestParam("id") Long id) {
        return roomService.deleteRoom(id);
    }

    @ApiOperation("添加直播间商品")
    @GetMapping("/addRoomSpu")
    public BaseResp addRoomSpu(@RequestParam("roomId") Long roomId, @RequestParam("spuId") Long spuId) {
        return roomService.addRoomSpu(roomId, spuId);
    }

    @ApiOperation("删除直播间商品")
    @GetMapping("/deleteRoomSpu")
    public BaseResp deleteRoomSpu(@RequestParam("roomSpuId") Long roomSpuId) {
        return roomService.deleteRoomSpu(roomSpuId);
    }

    @ApiOperation("设置直播间商品序号")
    @PostMapping("/editRoomSpuSorts")
    public BaseResp editRoomSpuSorts(@RequestBody RoomSpuReq req) {
        return roomService.editRoomSpuSorts(req);
    }

    @ApiOperation("直播间商品上架下架")
    @GetMapping("/editRoomSpuStatus")
    public BaseResp editRoomSpuStatus(@RequestParam("roomSpuId") Long roomSpuId, @RequestParam("status") Byte status) {
        return roomService.editRoomSpuStatus(roomSpuId, status);
    }

    @ApiOperation("获取直播间商品列表")
    @GetMapping("/getRoomSpuList")
    public ResultData<List<RoomSpuVO>> getRoomSpuList(@RequestParam("roomId") Long roomId) {
        return roomService.getRoomSpuList(roomId);
    }

    @ApiOperation("关注主播")
    @GetMapping("/attentionAnchor")
    public BaseResp attentionAnchor(@RequestParam("anchorUserId") Long anchorUserId) {
        return roomService.attentionAnchor(anchorUserId);
    }

    @ApiOperation("点赞主播")
    @GetMapping("/likeAnchor")
    public BaseResp likeAnchor(@RequestParam("roomId") Long roomId) {
        return roomService.likeAnchor(roomId);
    }

    @ApiOperation("直播间消息推送")
    @PostMapping("/sendRoomMessage")
    public BaseResp sendRoomMessage(@RequestBody WsSendToUserReq req) {
        return roomService.sendRoomMessage(req);
    }

    @ApiOperation("直播开始录制")
    @GetMapping("/startRecord")
    public BaseResp startRecord(@RequestParam("cname") String cname,@RequestParam("roomId") Long roomId) {
        return roomService.startRecord(cname,roomId);
    }

    @ApiOperation("停止录制")
    @GetMapping("/stopRecord")
    public BaseResp stopRecord(@RequestParam("cname") String cname,@RequestParam("roomId") Long roomId) {
        return roomService.stopRecord(cname,roomId);
    }

    @ApiOperation("查询录制")
    @GetMapping("/queryRecord")
    public ResultData<QueryRecordResp> queryRecord(@RequestParam("roomId") Long roomId) {
        return roomService.queryRecord(roomId);
    }

    @ApiOperation("直播token生产")
    @GetMapping("/getLiveToken")
    public ResultData<String> getLiveToken(@AuthenticationPrincipal User user, @RequestParam("roomId") Long roomId,@RequestParam("role") int role) {
        return new ResultData<>(roomService.getLiveToken(user, roomId,role));
    }

    @ApiOperation("获取直播间回放")
    @GetMapping("/getRoomPlayback")
    public ResultData<List<String>> getRoomPlayback(@RequestParam("roomId") Long roomId) {
        return roomService.getRoomPlayback(roomId);
    }
}
